package com.lobstar.xrpc.example.services;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.lobstar.xrpc.service.annotation.SMethod;
import com.lobstar.xrpc.service.annotation.SParam;

public class Add {

	@SMethod("sample_add")
	public Integer add(@SParam("a")Integer a,@SParam("b")Integer b) throws InterruptedException {
		Thread.sleep(1000);
		return a+b;
	}
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	@SMethod("format")
	public Date format(@SParam("date")String date) throws ParseException {
		return sdf.parse(date);
	}

	@SMethod("list")
	public List<String> tolist() {
		List<String> list = new ArrayList<String>();
		list.add("3");
		list.add("a");
		return list;
	}
	@SMethod("p_list")
	public List<Integer> list() {
		List<Integer> list = new ArrayList<Integer>();
		list.add(1);
		list.add(1);
		list.add(2);
		list.add(3);
		list.add(5);
		return list;
	}
	@SMethod("alist")
	public List<A> aList() {
		List<A> list = new ArrayList<A>();
		list.add(new A(3,"x"));
		list.add(new A(5,"y"));
		return list;
	}
	@SMethod("getA")
	public A getA(@SParam("a1")Integer a1,@SParam("a2")String a2) {
		return new A(a1,a2);
	}

	@SMethod("plus")
	public int plus(@SParam("a")Integer a,@SParam("b")Integer b) {
		return a+b;
	}
	@SMethod("divide")
	public double divide(@SParam("a")Integer a,@SParam("b")Integer b) {
		return a/b;
	}


	class A {
		private Integer a1;
		private String a2;

		public A(Integer a1,String a2) {
			this.a1=a1;
			this.a2=a2;
		}

		public Integer getA1() {
			return a1;
		}
		public void setA1(Integer a1) {
			this.a1 = a1;
		}
		public String getA2() {
			return a2;
		}
		public void setA2(String a2) {
			this.a2 = a2;
		}
	}
}
